package aControllerLayer;

import java.io.IOException;

import aModelLayer.Game;
import aModelLayer.Load;
import aModelLayer.Menu;
import aModelLayer.Save;
import aViewLayer.PauseView;
import aViewLayer.View;
import aaGame.GameEngine;
import azServiceLayer.Input;

public class PauseMenuController extends Controller {
	
	GameEngine mEngine;
	Game mModel;
	private PauseView mPauseView;
	private int mKey = -100;
	
	Menu mainMenu;
	
	private Menu currentMenu;
	
	public PauseMenuController(Game model, GameEngine engine){
		mModel = model;
		mEngine = engine;
		
		mainMenu = new Menu(new String[]{"Items", "Equipment", "Magic", "Stats",
				"Options", "Save", "Load", "Quit"});
		
		currentMenu = mainMenu;
		
		mPauseView = new PauseView(mModel, this);
		
		
	}

	@Override
	public void update() {
		
	}

	@Override
	public void keyPressed(int key) {
		switch(key){		
		case Input.DOWN: 
			currentMenu.nextOption();
			break;
		case Input.UP:
			currentMenu.previousOption();
			break;
		case Input.Z:
			if (currentMenu == mainMenu) {
				switch(currentMenu.getCurrentOption()){
				case "Items":
					;
					break;
				case "Equipment":
					;
					break;
				case "Magic":
					;
					break;
				case "Stats":
					;
					break;
				case "Options":
					;
					break;
				case "Save":
					try {
						new Save(mModel);
					} catch (IOException e) {
						// TODO Auto-generated catch block
						e.printStackTrace();
					}
					break;
				case "Load":
					new Load(mModel);
					break;
				case "Quit":
					mEngine.mRoomController.stopMusic();
					mEngine.setController(Controller.TitleMenuController);
					mEngine.currentController.playMusic();
					break;
				}
				break;
			}
			break;
		case Input.ESCAPE:
			if (currentMenu == mainMenu) {
				currentMenu.setOption(0);
				mEngine.setController(Controller.RoomController);
				mEngine.printControllerName();
			} 
			break;
		}
	}

	@Override
	public void keyReleased(int key) {
		if (key == mKey)
			mKey = -100;
	}
	
	@Override
	public View getView() {
		return mPauseView;
	}
	
	public Menu getMainMenu() {
		return mainMenu;
	}

	@Override
	public void playMusic() {
		// TODO Auto-generated method stub
		
	}
}
